
package com.seekting.study;

public abstract class SingletonTest<T> {

    private T instance;

    protected abstract T create();

    public final T get() {
        synchronized (this) {

            if (instance == null) {
                instance = create();
            }
            return instance;
        }

    }

    public static class ManagerTest {

    }

    public static class SingletonManager extends SingletonTest<ManagerTest> {

        @Override
        protected ManagerTest create() {
            ManagerTest manager = new ManagerTest();
            return manager;
        }
    }

    public final static SingletonManager singletonManager = new SingletonManager();

    public static void main(String[] args) {
        System.out.println(singletonManager.get() == singletonManager.get());
    }
}
